﻿/*
* get the artist content of a JSON file using Ajax 
*
*/


$(document).ready(function () {
    getArtistsAjax();

});


function getArtistsAjax() {
    jQuery.ajax({
        type: 'GET',
        url: 'http://lexicon-software-apps.com/ArtService.svc/GetArtists',
        dataType: "jsonp",
        success: function (result) {
            updateArtists(result);
        },
        error: function (result) {
            requestFailed(result);
        }
    });
}


function updateArtists(artists) {
    var artistDiv = document.getElementById("arts");
    for (var i = 0; i < artists.length; i++) {
        var artist = artists[i];
        var div = document.createElement("div");
        div.setAttribute("class", "artItem");
        div.innerHTML = artist.Name + " was born in " + artist.PlaceOfBirth + " on " + artist.DateOfBirthLongString;
        artistDiv.appendChild(div);
    }
}

function requestFailed(results) {
    alert("The artist information you requested is not available");
}


